#@web_layout?()
#define css()
<link rel="stylesheet" type="text/css" href="#(contextPath)/assets/front/web/css/layer.css?#(getUUID())" />
<link rel="stylesheet" type="text/css" href="#(contextPath)/assets/front/web/css/main.css?#(getUUID())" />
<link rel="stylesheet" type="text/css" href="#(contextPath)/assets/front/web/script/upload/webuploader.css" />
<style>
	.tipso_style{
		border:0
	}
</style>
#end
#define content()
<div class="c-article" style="min-height:100%;">
    <form id="editTaskForm">
        <input type="hidden" id="id" name="task.id" value="#(task.id??'')">
    <div class="g-info">
        <div class="u-title">编辑任务信息</div>
        <div class="m-panel" style="border-radius: 2px">
            <div class="m-row">
                <div class="u-row-title">任务标题:</div>
                <div class="u-row-box">
                    <div class="u-row-box-input">
                    #(task.task_title??"")
                    </div>
                </div>
            </div>
            <div class="m-row">
                <div class="u-row-title">任务时间:</div>
                <div class="u-row-box">
                    <div class="u-row-box-input">
                    	#date(task.task_start_time,"YYYY-MM-dd")至#date(task.task_end_time,"YYYY-MM-dd")
                    </div>
                </div>
            </div>
            <div class="m-row">
                <div class="u-row-title">任务说明:</div>
                <div class="u-row-box">
                    <div class="u-row-box-textarea">
                        <textarea id="task_description" placeholder="请输入任务说明，400字符以内"
                        name="desc" class="u-row-cell-textarea" maxlength="400">#(task.task_description??"")</textarea>
                    </div>
                </div>
            </div>
            
            #--
            #if(task.h5_type==2)
            <div class="m-row" id="pic_panel">
                <div class="u-row-title">图片素材:</div>
                <div class="u-row-box">
                    <div class="u-row-box-upload" id="upload">
                        <div class="" id="fileClick" >上传图片(可多图，图片大小限制1M以内)</div>
                        <div style="display: none" id="hiddenFiles">
							#for(x:sources)
								<input type="hidden" name="source" data-source="#(x.id??0)" id="source_WU_FILE_#(for.index)" value="#(x.source??'')">
							#end
                        </div>
                        <input type="file" id="files" style="display: none">
                        <div class="u-row-cell-upload" id="uploaded">
							#for(x:sources)
								<div class="u-row-cell-upload-btn" id="wrpper_WU_FILE_#(for.index)">
									<div id="WU_FILE_#(for.index)" class="u-row-cell-upload-btn-border" style="height: 95%; background: url(&quot;#(x.source??'')&quot;) center center / contain no-repeat;"></div>
									<div style="text-align:center;"><a href="javascript:;" onclick="deleteWrapper('WU_FILE_#(for.index)')" style="color:#c5c2c2">删除</a></div>
								</div>
							#end
                        </div>
                    </div>
                </div>
            </div>
            #end
            --#
            <div class="m-row">
                <div class="task-next" id="editTaskBtn" >保存</div>
                <input type="hidden" value="#(task.id??0)" name="taskId"> 
            </div>
        </div>
    </div>
    </form>
</div>
#end
#define script()
<script src="#(contextPath)/assets/front/web/script/ajax.js"></script>
<script src="#(contextPath)/assets/front/web/script/webuploader.js"></script>
<script type="text/javascript">

function deleteWrapper(id){
	layer.confirm("确定要删除当前图片信息么？", {
        btn: ['确定','取消'] //按钮
    }, function(){
    	var sourceId = $("#source_"+id).attr("data-source");
    	if(sourceId){
    		$.ajax({
                type:"post",
                url:"/platform/task/deleteTaskSource",
                datatype:"json",
                data:{
                	sourceId: sourceId,
                },
                success:function(resp){
                	layer.alert(resp.msg);
                	$("#wrpper_"+id).remove();
                	$("#source_"+id).remove();
                }
        	});
    	}else{
    		layer.closeAll('dialog');
    		$("#wrpper_"+id).remove();
        	$("#source_"+id).remove();
    	}
    });
}

function initUploader(){
	
	
	var srcStr;
    var uploader = WebUploader.create({
        auto: true,
        duplicate:true,
        swf:  '#(contextPath)/assets/front/web/script/upload/Uploader.swf',
        server:'#(contextPath)/qiniu/upload',
        pick: {
            id:'#fileClick'
        },
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
        }
    });
    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {
        
    	var up=$("#uploaded");
        // 创建缩略图
        // thumbnailWidth x thumbnailHeight 为 100 x 100
        uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }
            var fileNum = up.children().length;
            file_id ="WU_FILE_"+fileNum;
            srcStr=src;
            up.append('<div class="u-row-cell-upload-btn" id="wrpper_'+file_id+'"><div id='+file_id+' class="u-row-cell-upload-btn-border" >正在上传</div></div>')
            var delLink = "<div style='text-align:center;'><a href='javascript:;' onclick=deleteWrapper('"+file_id+"') style='color:#c5c2c2'>删除</a></div>";
            var c=$("#"+"WU_FILE_"+fileNum);
            c.after(delLink);
            c.css('height',"95%");
            var input=$("#hiddenFiles");
            input.append('<input type="hidden" name="source" id="source_'+file_id+'">');
        }, "100", "100" );
    });
    //文件上传成功处理
    uploader.on( 'uploadSuccess', function( file,resp ) {
    	var up=$("#uploaded");
    	var fileNum = up.children().length-1;
        var c=$("#WU_FILE_"+fileNum);
        console.log(c);
        c.html("");
        console.log(resp._raw);
        c.css('background','url('+resp._raw+') center/contain no-repeat'); 
        var e=$("#source_"+"WU_FILE_"+fileNum);
        e.val(resp._raw);
    });
    //文件上传失败处理
    uploader.on( 'uploadError', function( file ) {
    	layer.alert(file.name+"上传失败！！")
    });
    // 文件上传过程中创建进度条实时显示。
    uploader.on( 'uploadProgress', function( file, percentage ) {
    });

}


    $(document).ready(function(){
    	initUploader();
    	$("#editTaskBtn").on("click",function(){
    		$.ajax({
    	        type:"post",
    	        url:"/platform/task/doUpdateTaskSource",
    	        datatype:"json",
    	        data:$("#editTaskForm").serialize(),
    	        success:function(resp){
    	        	layer.alert(resp.msg);
    	        }
    		});
    	});
    });
</script>

#end